package com.example.smartf.controller;

import com.example.smartf.model.mysql.Deviceinfo;
import com.example.smartf.service.UserdevService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 关于用户与设备之间的对照关系的管理
 * 体现在MongoDB中User表
 * 控制层
 */
@Api("用户设备管理")
@RestController
@CrossOrigin(origins = "*")

public class UserdevController {

    @Autowired
    private UserdevService userdevService;

    //用户查询拥有设备
    @ApiOperation("用户查询拥有设备")
    @ApiImplicitParam(name = "username", value = "用户名（邮箱号）", dataType = "String",paramType = "query")
    @PostMapping(value = "/userdev/showdev")
    public List<Deviceinfo> showdevs(@RequestParam("username") String username){
        return userdevService.showUserDev(username);
    }


    //用户增加设备
//    @ApiOperation("用户增加设备")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "username", value = "用户名（邮箱号）", dataType = "String",paramType = "query"),
//            @ApiImplicitParam(name = "deviceID", value = "用户未拥有的设备ID", dataType = "String",paramType = "query"),
//            @ApiImplicitParam(name = "kind", value = "该设备所培育作物的种类", dataType = "String",paramType = "query"),
//            @ApiImplicitParam(name = "devicename", value = "给设备的别名", dataType = "String",paramType = "query"),
//            @ApiImplicitParam(name = "remarks", value = "设备的备注", dataType = "String",paramType = "query")
//    })
//    @PostMapping(value = "/userdev/adddev")
//    public String addDev(@RequestParam("username") String username,
//                         @RequestParam("deviceID") String deviceID,
//                         @RequestParam("kind") String kind,
//                         @RequestParam("devicename") String devicename,
//                         @RequestParam("remarks") String remarks){
//        return userdevService.addUserDev(username,deviceID,kind,devicename,remarks);
//    }




    //用户删除设备
//    @ApiOperation("用户删除设备")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "username", value = "用户名（邮箱号）", dataType = "String",paramType = "query"),
//            @ApiImplicitParam(name = "deviceID", value = "用户已拥有的设备ID", dataType = "String",paramType = "query")
//    })
//    @PostMapping(value = "/userdev/deldev")
//    public String delDev(@RequestParam("username") String username,
//                         @RequestParam("deviceID") String deviceID){
//        return userdevService.delUserDev(username,deviceID);
//    }



}
